package cn.lhjl.day09.多线程;

public class ChiHuo extends Thread{
    BaoZhi baoZhi;

    public ChiHuo(BaoZhi baoZhi) {
        this.baoZhi = baoZhi;
    }

    @Override
    public void run() {
        while (true){
            synchronized (baoZhi){
                if (!baoZhi.flag){
                    try {
                        baoZhi.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println("吃包子");
                baoZhi.flag=false;
                baoZhi.notify();
            }
        }
    }
}
